<template>
  <view class="location-container">
	  当前用户：{{curuser.nickname}}<br/>
	  当前用户：{{curuser.openid}}<br/>
		<view @click="join">报名</view>
		<view @click="sign">签到</view>
		<view @click="gift">领礼品</view>
		<view @click="draw">抽奖</view>
  </view>
</template>

<script>
export default {
  data() {
    return {
		curuser:'',
      locationStatus: '准备定位...',
      location: {
        latitude: '',
        longitude: '',
        address: ''
      }
    }
  },
  
  async onLoad() {
	  let link = window.location.href;
	  // //判断link中有没有code=字符串
	  if(link.indexOf('code=') == -1){
	  	//没有code则引导关注者打开如下页面链接，授权
	  	let uri = 'https://app.buildream.club/signup'
	  	//let uri ='http://47.108.115.71:9361/signup'
	  	uri = encodeURIComponent( uri );
	  	let appid = "wx070fe96753c674a0";
	  	let authURL = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${uri}&response_type=code&scope=snsapi_base&state=123#wechat_redirect`;
	  	//重新引导回本页面，然后又重新判断link.indexOf('code=') == -1
	  	window.location.href = authURL;
	  }else{
	  	 //回调函数已经执行 返回的链接存在code= 地址解析
	  	let temp = link.split("code=")[1];
	  	let code = temp.split("&")[0];
	  	let data = { code:code}
	  	//对getUserOpenid云函数发送请求传参code获取用户openid
	  	let res = await this.$api.request("v2/guest/oauth2accessToken2",data);
		this.curuser = res.data
	  }
	  
    this.getLocation()
  },
  
  methods: {
    getLocation() {
      
    },
	join(){uni.navigateTo({url:'./ActList?id='+this.curuser.openid})},
	sign(){
		uni.navigateTo({url:'./signActList?id='+this.curuser.openid})
	},
	gift(){uni.navigateTo({url:'./signRecGift?id='+this.curuser.openid})},
	
	draw(){uni.navigateTo({url:'./signForDraw?id='+this.curuser.openid})}
  }
}
</script>

<style lang="scss">
.location-container {
  padding: 20px;
  
  .status-box {
    text-align: center;
    margin-bottom: 30px;
    
    .status-text {
      font-size: 16px;
      color: #666;
    }
  }
  
  .location-info {
    background: #fff;
    border-radius: 8px;
    padding: 15px;
    margin-bottom: 30px;
    
    .info-item {
      margin-bottom: 10px;
      
      .label {
        color: #666;
      }
      
      .value {
        color: #333;
        margin-left: 10px;
      }
    }
  }
  
  .locate-btn {
    background: #007AFF;
    color: #fff;
    
    &:active {
      background: #0062cc;
    }
  }
}
</style>